package com.yunxi.service.dubboService.impl.sys;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.model.sys.User;
import com.yunxi.service.localService.sys.UserService;
import com.yunxi.sys.pojo.RoleUserVO;
import com.yunxi.sys.pojo.UserVO;
import com.yunxi.sys.service.UserDubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import java.lang.reflect.InvocationTargetException;
import java.sql.Wrapper;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.Condition;

/**
 * Created by xuruzi on 2017/5/3.
 */
public class UserDubboServiceImpl implements UserDubboService {
    @Autowired
    @Qualifier(value = "userServiceImpl")
    UserService userService;

    public UserVO saveCas(UserVO tmUser, LoginInfo sysUser) throws Exception {
        return userService.saveCas(tmUser, sysUser);
    }

    public UserVO save(UserVO user) throws Exception {
        User u = new User();
        BeanUtils.copyProperties(user, u);
        userService.save(u);
        user.setUserId(u.getUserId());
        return user;
    }

    @Override
    public UserVO getCasId(String id) {
        return userService.getCasId(id);
    }

    @Override
    public UserVO findUserByUserCode(Map map) {
        return userService.findUserByUserCode(map);
    }

    @Override
    public PageInfo<User> page(Map<String, Object> map) {
        return userService.pageByMap(map);
    }

    @Override
    public void removeByList(List<UserVO> userList) throws IllegalAccessException, InvocationTargetException, InstantiationException {
        userService.removeByListVo(userList);
    }

    @Override
    public UserVO saveOrUpdate(UserVO user) {
        User u = new User();
        BeanUtils.copyProperties(user, u);
        userService.saveOrUpdate(u);
        return user;
    }

    @Override
    public UserVO findPdaUserByUserCode(Map map) {
        return userService.findPdaUserByUserCode(map);
    }

    @Override
    public UserVO getByUserCode(String storageStaffPhone) {
        return userService.getByUserCode(storageStaffPhone);
    }

    @Override
    public void update(UserVO userVO) {
        User user = new User();
        BeanUtils.copyProperties(userVO, user);
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("USER_ID", user.getUserId());
        userService.update(user, wrapper);
    }

    @Override
    public List exportExcel(Map<String, Object> params) {
        return userService.listBy(params);
    }

    @Override
    public void resetPassword(UserVO user) throws Exception {
        userService.resetPassword(user);
    }

    @Override
    public void updatePassword(UserVO user) throws Exception {
        userService.updatePassword(user);
    }
}
